package HGbet;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import DXQclient.DXQclientManager;
import HGclient.GameDetails;
import HGclient.HGODDSINDEX;
import P8.AccountManager;
import P8.Common;
import P8.P8Http;
import P8.StoneAge;

public class BetWindow extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 88888888L;
	
    private JLabel labelDXQ = new JLabel("网址:");
    //private JTextField textFieldAddress = new JTextField(15);  
    
    String str1[] = {"大球", "小球"};
    
    private DXQclientManager dxqClientManager = null;
    private HGbethttp hgBethttp = null;
    
    private JComboBox jcb = new JComboBox(str1); 
	
    private JLabel labelLeague = new JLabel("联赛:");
    private JTextField textFieldLeague = new JTextField(15);  
    
    private JLabel labelTeam = new JLabel("球队:");
    private JTextField textFieldTeam = new JTextField(15);  
    

    
    private JLabel labelratio = new JLabel("赔率:");
    private JTextField textFieldratio = new JTextField(15);  
    

    private JLabel labelminbet = new JLabel("单注最低:");
    private JTextField textFieldminbet = new JTextField(15);  
    
    
    private JLabel labelmaxbet = new JLabel("单注最高:");
    private JTextField textFieldmaxbet = new JTextField(15);  
    
    private JLabel labelamount = new JLabel("交易金额:");
    private JTextField textFieldamount = new JTextField(15);  

    private Button addConfirmBtn = new Button("确定交易");
    private Button refreshBtn = new Button("刷新");
    
    
    GameDetails onegame = null;

    
	public BetWindow(DXQclientManager manager, HGbethttp http)  
    {  
		setTitle("交易");  
		dxqClientManager = manager;
		hgBethttp = http;
        intiComponent();  
        
    }  
	
	

	public void setgame(GameDetails g){
		onegame = g;
		
		Vector<String[]> odds = onegame.getodds();
		
		int latestodd = odds.size() - 1;
		
		String[] odd = odds.elementAt(latestodd);
		
		
		
		
		textFieldLeague.setText(onegame.league);
		textFieldTeam.setText(onegame.teamh+"-vs-"+ onegame.teamc);
		
		String gnum = "";
		String type = "";
		if(str1[jcb.getSelectedIndex()].equals("大球")){
			gnum = onegame.gnumc;
			type = "C";
		}else{
			gnum = onegame.gnumh;
			type = "H";
		}
		
		
		
		HashMap<String, String> map = (HashMap<String, String>) hgBethttp.getBetDXQdetails(odd[HGODDSINDEX.GID.ordinal()], gnum, type);
		textFieldratio.setText(map.get("ratio"));
		textFieldminbet.setText(map.get("minbet"));
		textFieldmaxbet.setText(map.get("maxbet"));
		
		
	}
    
    
    /** 
     * 初始化窗体组件 
     */  
    private void intiComponent()  
    {  

		final Container container = getContentPane();
		
		container.setLayout(new BorderLayout());
		
		JPanel panelNorth = new JPanel(new GridLayout(8, 2));

        container.add(panelNorth, BorderLayout.NORTH);  
        

        
        
        refreshBtn.addActionListener(new ActionListener() {  
        	  
            @Override  
            public void actionPerformed(ActionEvent e) {  

        		Vector<String[]> odds = onegame.getodds();
        		
        		int latestodd = odds.size() - 1;
        		
        		String[] odd = odds.elementAt(latestodd);
            	
        		String gnum = "";
        		String type = "";
        		if(str1[jcb.getSelectedIndex()].equals("大球")){
        			gnum = onegame.gnumc;
        			type = "C";
        		}else{
        			gnum = onegame.gnumh;
        			type = "H";
        		}
        		
        		
        		
        		HashMap<String, String> map = (HashMap<String, String>) hgBethttp.getBetDXQdetails(odd[HGODDSINDEX.GID.ordinal()], gnum, type);
        		textFieldratio.setText(map.get("ratio"));
        		textFieldminbet.setText(map.get("minbet"));
        		textFieldmaxbet.setText(map.get("maxbet"));
            }  
        });  
        
        

        
        
        jcb.setSelectedIndex(0);
        
        jcb.addItemListener(new ItemListener() {


			@Override
			public void itemStateChanged(ItemEvent e) {
				// TODO Auto-generated method stub
               // int index = jcb.getSelectedIndex();
                String content = jcb.getSelectedItem().toString();
                
                
                
        		Vector<String[]> odds = onegame.getodds();
        		
        		int latestodd = odds.size() - 1;
        		
        		String[] odd = odds.elementAt(latestodd);
            	
        		String gnum = "";
        		String type = "";
        		if(content.equals("大球")){
        			gnum = onegame.gnumc;
        			type = "C";
        		}else{
        			gnum = onegame.gnumh;
        			type = "H";
        		}
        		
        		
        		
        		HashMap<String, String> map = (HashMap<String, String>) hgBethttp.getBetDXQdetails(odd[HGODDSINDEX.GID.ordinal()], gnum, type);
        		textFieldratio.setText(map.get("ratio"));
        		textFieldminbet.setText(map.get("minbet"));
        		textFieldmaxbet.setText(map.get("maxbet"));
                
                
                
			}
        });
        
        
        
        
        panelNorth.add(labelDXQ);
        panelNorth.add(jcb);

        
        panelNorth.add(labelLeague);
        panelNorth.add(textFieldLeague);

        panelNorth.add(labelTeam);
        panelNorth.add(textFieldTeam);
        

        
        
        panelNorth.add(labelratio);
        panelNorth.add(textFieldratio);
        
        panelNorth.add(labelminbet);
        
        panelNorth.add(textFieldminbet);
        
        
        panelNorth.add(labelmaxbet);
        panelNorth.add(textFieldmaxbet);
        
        panelNorth.add(labelamount);
        
        panelNorth.add(textFieldamount);
        
        panelNorth.add(addConfirmBtn);
        
        panelNorth.add(refreshBtn);       
        
        

        setVisible(false);  
        
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);  

        setBounds(100, 100, 450, 250); 

    }  
	

}
